<template>
  <div class="login-wrapper">
    <div class="custom-topHr"></div>

    <div class="logo-box">
      <img class="logo" src="@/assets/images/logo1.png">
    </div>
    <div class="login-box">
      <customForm :type="type"/>

      <div class="submit-box">
        <button class="submit-btn" @click="bind_mobile">提 交</button>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import customForm from "./form";
import constant from "@/utils/constant.js";
// 引用API文件
import http from "@/utils/http.js";

export default {
  name: "bindmobile",
  data() {
    return {
      type: "bindMobile"
    };
  },
  components: {
    customForm
  },
  methods: {
    bind_mobile() {
      const reg = 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/;
      let mobile = this.$store.state.loginform.mobile;
      if (mobile == "") {
        this.$message({
          message: "手机号不能为空",
          type: "warning"
        });
        return;
      }
      if (!reg.test(mobile)) {
        this.$message({
          message: "请输入正确的手机号",
          type: "warning"
        });
        return;
      }

      let sms_code = this.$store.state.loginform.sms_code;

      if (sms_code == "") {
        this.$message({
          message: "请填写验证码",
          type: "warning"
        });
        return;
      }

      console.log(sms_code);

      http.post(this, {
        url: "ucenter/bind_mobile",
        data: {
          mobile: mobile,
          code:sms_code,
          token:localStorage.getItem("user_token")
        },
        dataType: "json",
        success: function(data) {
          console.log("绑定手机:", data);
          if (data.status == 1) {
              let user_info = data.info;
              localStorage.setItem("user_name", user_info.username);
              localStorage.setItem("user_token", user_info.token);
              localStorage.setItem("user_type", user_info.user_type);
            this.$message({
              message: "绑定成功",
              type: "success",
              center: true
            });
            window.location.href = '/';
          } else {
            this.$message.error(data.info);
          }
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
</style>
